package com.hdx.server.mapper;


import com.github.pagehelper.Page;
import com.hdx.common.enumeration.OperationType;
import com.hdx.model.dto.SetmealPageQueryDTO;
import com.hdx.model.entity.Setmeal;
import com.hdx.model.vo.DishItemVO;
import com.hdx.model.vo.SetmealVO;
import com.hdx.server.annotation.AutoFill;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface SetmealMapper {


    @Select("select count(id) from setmeal where category_id = #{categoryId}")
    Integer getCountByCategoryId(Long id);

    @AutoFill(OperationType.UPDATE)
    void update(Setmeal setmeal);


    @AutoFill(OperationType.INSERT)
    void insert(Setmeal setmeal);


    Page<SetmealVO> pageQuery(SetmealPageQueryDTO setmealPageQueryDTO);


    @Select("select * from setmeal where id = #{id}")
    Setmeal getById(Long id);


    @Delete("delete from setmeal where id = #{id}")
    void deleteById(Long setmealId);


    SetmealVO getByIdWithDish(Long id);


    List<Setmeal> list(Setmeal setmeal);



    List<DishItemVO> getDishItemBySetmealId(Long setmealId);



    
    @Select("select sd.name, sd.copies, d.image, d.description " +
            "from setmeal_dish sd left join dish d on sd.dish_id = d.id " +
            "where sd.setmeal_id = #{setmealId}")
    Integer getStemealCountByCategoryId(Long id);


    Integer countByMap(Map map);
}
